const {
    DayPlan
} = require('../../../model/plan/dayPlan');

function getdate(times) {
    var now = new Date(times),
        y = now.getFullYear(),
        m = now.getMonth() + 1,
        d = now.getDate();
    return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
}


module.exports = async (req, res) => {
    let pageSize = req.fields.pageSize
    let currentPage = req.fields.current

    // 获取post参数
    let data
    let total
    data = await DayPlan.find().sort('-createTime').skip((currentPage - 1) * pageSize).limit(pageSize);
    total = await DayPlan.find().sort('-createTime').count()
    let list = data.map((item) => {
        return { id: item.id, username: item.username, phone: item.phone, planName: item.planName, planType: item.planType, startTime: getdate(item.startTime), endTime: getdate(item.endTime), achieveStatus: item.achieveStatus, createTime: getdate(item.createTime) }
    })
}